package com.why.blog.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
@Data
public class JwtUser implements UserDetails {
    private String userId;

    private String userName;

    private String userPass;

    private Collection<? extends GrantedAuthority> authorities;
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }


    public JwtUser() {
    }

    //直接使用user创建HaloUserVO的构造器
    public JwtUser(HaloUser user) {
        userId = user.getUserId();
        userName = user.getUserName();
        userPass = user.getUserPass();
        authorities = Collections.singleton(new SimpleGrantedAuthority(user.getRole()));
    }



    @Override
    public String getPassword() {
        return userPass;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    public String getUserId() {
        return userId;
    }

    // 账号是否未过期，默认是false，
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    // 账号是否未锁定，默认是false
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    // 账号凭证是否未过期，默认是false
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    // 是否能使用，默认也是false，
    @Override
    public boolean isEnabled() {
        return true;
    }
}
